(function() {
  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
    __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.MessagesView = (function(_super) {

    __extends(MessagesView, _super);

    function MessagesView() {
      this.afterLoad = __bind(this.afterLoad, this);
      return MessagesView.__super__.constructor.apply(this, arguments);
    }

    MessagesView.prototype.initialize = function() {
      MessagesView.__super__.initialize.apply(this, arguments);
      this.setElement("#main");
      this.model.bind("change", this.render);
      return this.model.fetch();
    };

    MessagesView.prototype.render = function() {
      var _this = this;
      return this.GetTemplate(SiteMap.Messages.UserListingEmptyTemplate, function(template) {
        $(_this.el).html(template(_this.model.toJSON()));
        _this.startLoading();
        _this.renewScrolling();
      });
    };

    MessagesView.prototype.events = {
      "click ul li": "show",
      "click button.buttons": "back",
      "click .sorting a": "sort"
    };

    MessagesView.prototype.show = function(event) {
      event.preventDefault();
      this.Navigate(SiteMap.Messages.MessageListing + "?senderId=" + $(event.currentTarget).data("sender-id"), true);
    };

    MessagesView.prototype.back = function(event) {
      event.preventDefault();
      return this.Navigate(SiteMap.Home.Index, true);
    };

    MessagesView.prototype.afterLoad = function(data) {
      var _this = this;
      return this.GetTemplate(SiteMap.Messages.UserListingTemplate, function(compiledTemplate) {
        return $(_this.el).find("ul.user-listing").append(compiledTemplate(data));
      });
    };

    MessagesView.prototype.sort = function(event) {
      var element;
      event.preventDefault();
      element = $(event.currentTarget);
      this.model.set("Column", element.data("sort-option"), {
        silent: true
      });
      this.model.set("Direction", element.data("sort-direction"), {
        silent: true
      });
      this.model.set("Page", 1, {
        silent: true
      });
      return this.model.fetch();
    };

    return MessagesView;

  })(ScrollPagingView);

}).call(this);
